home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Transformations / Using the World Transformation / GDITEST19.dpr
Encoding:
Text File  |  2003-10-15  |  3.2 KB  |  118 lines

  1. program GDITEST19;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   Rect: TGPRect;
  14.   Pen: TGPPen;
  15. begin
  16.   graphics := TGPGraphics.Create(DC);
  17.  
  18.   // We start by creating a 50 by 50 rectangle and locating it at the origin
  19.   // (0, 0). The origin is at the upper-left corner of the client area.
  20.  
  21.   Rect := MakeRect(50, 50, 50, 50);
  22.   Pen := TGPPen.Create(MakeColor(255, 255, 0, 0), 0);
  23.   graphics.DrawRectangle(pen, rect);
  24.  
  25.  
  26.   // The following code applies a scaling transformation that expands the
  27.   // rectangle by a factor of 1.75 in the x direction and shrinks the rectangle
  28.   // by a factor of 0.5 in the y direction:
  29.  
  30.   graphics.ScaleTransform(1.75, 0.5);
  31.   graphics.DrawRectangle(pen, rect);
  32.   graphics.ResetTransform;
  33.   // The result is a rectangle that is longer in the x direction and shorter
  34.   // in the y direction than the original.
  35.  
  36.   // To rotate the rectangle instead of scaling it, use the following code
  37.   // instead of the preceding code:
  38.  
  39.   graphics.RotateTransform(28.0);
  40.   graphics.DrawRectangle(pen, rect);
  41.   graphics.ResetTransform;
  42.   //To translate the rectangle, use the following code:
  43.  
  44.   graphics.TranslateTransform(150.0, 150.0);
  45.   graphics.DrawRectangle(pen, rect);
  46.   graphics.ResetTransform;
  47.  
  48.   Pen.Free;
  49.   graphics.Free;
  50. end;
  51.  
  52.  
  53. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  54. var
  55.   Handle: HDC;
  56.   ps: PAINTSTRUCT;
  57. begin
  58.   case message of
  59.     WM_PAINT:
  60.       begin
  61.         Handle := BeginPaint(Wnd, ps);
  62.         OnPaint(Handle);
  63.         EndPaint(Wnd, ps);
  64.         result := 0;
  65.       end;
  66.  
  67.     WM_DESTROY:
  68.       begin
  69.         PostQuitMessage(0);
  70.         result := 0;
  71.       end;
  72.  
  73.    else
  74.       result := DefWindowProc(Wnd, message, wParam, lParam);
  75.    end;
  76. end;
  77.  
  78. var
  79.   hWnd     : THandle;
  80.   Msg      : TMsg;
  81.   wndClass : TWndClass;
  82. begin
  83.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  84.    wndClass.lpfnWndProc    := @WndProc;
  85.    wndClass.cbClsExtra     := 0;
  86.    wndClass.cbWndExtra     := 0;
  87.    wndClass.hInstance      := hInstance;
  88.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  89.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  90.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  91.    wndClass.lpszMenuName   := nil;
  92.    wndClass.lpszClassName  := 'GettingStarted';
  93.  
  94.    RegisterClass(wndClass);
  95.  
  96.    hWnd := CreateWindow(
  97.       'GettingStarted',       // window class name
  98.       'Using the World Transformation',      // window caption
  99.       WS_OVERLAPPEDWINDOW,    // window style
  100.       Integer(CW_USEDEFAULT), // initial x position
  101.       Integer(CW_USEDEFAULT), // initial y position
  102.       Integer(CW_USEDEFAULT), // initial x size
  103.       Integer(CW_USEDEFAULT), // initial y size
  104.       0,                      // parent window handle
  105.       0,                      // window menu handle
  106.       hInstance,              // program instance handle
  107.       nil);                   // creation parameters
  108.  
  109.    ShowWindow(hWnd, SW_SHOW);
  110.    UpdateWindow(hWnd);
  111.  
  112.    while(GetMessage(msg, 0, 0, 0)) do
  113.    begin
  114.       TranslateMessage(msg);
  115.       DispatchMessage(msg);
  116.    end;
  117. end.
  118.